﻿using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SqlSugar; 

namespace Pear.Web.Core
{
    public class Startup : AppStartup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddJwt<JwtHandler>(enableGlobalAuthorize: true);

            services.AddCorsAccessor(); 

            services.AddControllersWithViews()
                   .AddInjectWithUnifyResult();

            services.AddSqlsugarSetup(App.Configuration); 
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseUnifyResultStatusCodes();

            app.UseHttpsRedirection();

            var provider = new FileExtensionContentTypeProvider();
            //provider.Mappings[".apk"] = "application/vnd.android.package-archive";//配置添加新的映射关系-Apk 
            //provider.Mappings[".log"] = "text/plain;charset=utf-8";
            provider.Mappings[".yml"] = "application/yaml";

            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider,//应用新的映射关系
            });

            app.UseRouting();

            app.UseCorsAccessor();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseInject(string.Empty);

            app.UseSpecificationDocuments();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}